<template>
  <el-dialog
    title="选择危险物质"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="JNPF-dialog JNPF-dialog_center"
    lock-scroll
    append-to-body
    width="1200px"
  >
    <el-row class="JNPF-common-search-box" :gutter="16">
  			<el-form @submit.native.prevent>
					<el-col :span="6">
						<el-form-item label="化学品名称">
							<el-input v-model="query.hxpmc" placeholder="化学品名称" clearable  />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="别名">
							<el-input v-model="query.bc" placeholder="别名" clearable  />
						</el-form-item>
					</el-col>
					<el-col :span="6">
					<el-form-item>
						<el-button type="primary" icon="el-icon-search" @click="init()">查询</el-button>
						<el-button icon="el-icon-refresh-right" @click="refresh()">重置</el-button>
					</el-form-item>
					</el-col>
				</el-form>
      <div class="JNPF-common-search-box-right">
        <el-tooltip
          effect="dark"
          :content="$t('common.refresh')"
          placement="top"
        >
          <el-link
            icon="icon-ym icon-ym-Refresh JNPF-common-head-icon"
            :underline="false"
            @click="refresh()"
          />
        </el-tooltip>
      </div>
    </el-row>
    <JNPF-table
      v-loading="listLoading"
      :data="list"
      hasC
      @selection-change="handleSelectionChange"
      :border="false"
    >
      <el-table-column prop="hxpmc" label="危险化学品名称" width="400" />
      <el-table-column prop="bc" label="别名" width="300" />
      <el-table-column prop="cas" label="CAS号" />
      <el-table-column prop="wxtx" label="危险特性" />
      <el-table-column prop="ljl" label="临界量/t" />
      <el-table-column prop="jzxs" label="校正系数β" />
    </JNPF-table>
    <pagination
      :total="total"
      :page.sync="listQuery.currentPage"
      :limit.sync="listQuery.pageSize"
      @pagination="init"
    />
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{
        $t("common.cancelButton")
      }}</el-button>
      <el-button type="primary" @click="select()">{{
        $t("common.confirmButton")
      }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import request from "@/utils/request";
import { GoodsList } from "@/api/extend/order";
export default {
  data() {
    return {
      visible: false,
      listLoading: true,
      list: [],
      total: 0,
      checked: [],
      query: {
        	hxpmc:undefined,
					bc:undefined,
      },
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "",
      },
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.visible = true;
      this.listLoading = true;
      let query = {
        ...this.listQuery,
        ...this.query,
      };
      request({
        url: `/api/System/WHPBZB`,
        method: "get",
        data: query,
      }).then((res) => {
        this.list = res.data.list;
        this.listLoading = false;
        this.total = res.data.pagination.total;
        this.$nextTick(() => {
          this.tableHeight = "100%";
        });
      });
    },
    refresh() {
      this.init();
    },
    select() {
      if (!this.checked.length) return;
      this.visible = false;
      this.$emit("refreshDataList", this.checked);
    },
    handleSelectionChange(val) {
      this.checked = val;
    },
  },
};
</script>
<style lang="scss" scoped>
>>> .el-dialog__body {
  height: 70vh;
  padding: 0 0 10px !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  .JNPF-common-search-box {
    margin-bottom: 0;
    .JNPF-common-search-box-right {
      padding: 10px 10px 0 0;
    }
  }
}
</style>